package com.keyinong.caizhengting.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.keyinong.caizhengting.R;
import com.keyinong.caizhengting.tools.HttpTools;
import com.keyinong.caizhengting.entity.JiluEntity;

import java.util.ArrayList;

/**
 * 菜单
 */

public class XiaofeiAdapter extends BaseAdapter {
    Context context;
    ArrayList<JiluEntity> jiluList;
    HttpTools httpTools = null;
    String code;

    public XiaofeiAdapter(Context context, ArrayList<JiluEntity> jiluList, String code) {
        super();
        this.context = context;
        this.jiluList = jiluList;
        this.code = code;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return jiluList.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return jiluList.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        final ViewHandle handle;
        if (view == null) {
            handle = new ViewHandle();
            view = LayoutInflater.from(context).inflate(R.layout.item_xiaofei, null);
            handle.tv_riqi = (TextView) view.findViewById(R.id.tv_riqi);
            handle.tv_time = (TextView) view.findViewById(R.id.tv_time);
            handle.tv_price = (TextView) view.findViewById(R.id.tv_price);
            handle.tv_tital = (TextView) view.findViewById(R.id.tv_tital);
//			handle.tv_sname=(TextView)view.findViewById(R.id.tv_sname);
            view.setTag(handle);
        } else {
            handle = (ViewHandle) view.getTag();
        }
//		if (code.equals("1")) {
//			handle.tv_tital.setText("充值");
//		}else if (code.equals("2")){
//			handle.tv_tital.setText("消费");
//		}else if (code.equals("3")){
//			handle.tv_tital.setText("退款");
//		}
        handle.tv_riqi.setText(jiluList.get(position).getRiqi());
        handle.tv_time.setText(jiluList.get(position).getTime());
//		handle.tv_price.setText(""+(int)(Double.parseDouble(jiluList.get(position).getNum())*10));
        handle.tv_price.setText("" + jiluList.get(position).getNum());
        handle.tv_tital.setText(jiluList.get(position).getName());
//		if (caidanList.get(position).getSname().equals("")||caidanList.get(position).getSname().equals("null")) {
//			handle.tv_sname.setText("");
//		}else {
//			handle.tv_sname.setText("("+caidanList.get(position).getSname()+")");
//		}

        return view;
    }

    class ViewHandle {
        /**
         * 抬头
         */
        TextView tv_tital;
        /**
         * 金额
         */
        TextView tv_price;
        /**
         * 日期
         */
        TextView tv_riqi;
        /**
         * 时间
         */
        TextView tv_time;
    }
}
